package com.bootlever.framework.core.web.jsp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
public class JspMvcConfiguration extends WebMvcConfigurerAdapter {

    private static final Logger logger = LoggerFactory.getLogger(JspMvcConfiguration.class);
    /**
     * 默认加载，如果要重写，则可以使用相同的名称覆盖
     * @return
     */
    @Bean(name = "jspViewResolver")
    @ConditionalOnMissingBean(name = "jspViewResolver")
    public ViewResolver jspViewResolver() {
        logger.info("加载JSP视图解析器，设置优先级为10");
        InternalResourceViewResolver internalResourceViewResolver = new InternalResourceViewResolver();
        internalResourceViewResolver.setPrefix("/WEB-INF/jsp/");
        internalResourceViewResolver.setSuffix(".jsp");
        internalResourceViewResolver.setOrder(10);
        return internalResourceViewResolver;
    }

}
